package cn.emernet.demo1.controller;

import cn.emernet.demo1.util.HttpRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MainController {

    @Value("${app2.address}")
    String app2Address;

    @Value("${app3.address}")
    String app3Address;

    @Value("${spring.application.name}")
    String appName;

    @GetMapping("hello")
    public String hello(String name) {
        return "hello " + name + " appName = " + appName;
    }

    @GetMapping("testLink3")
    public String testLinkByGet() {
        HttpRequest.sendGet(app2Address + "/hello");
        HttpRequest.sendGet(app3Address + "/hello");
        return "ok";
    }

    @PostMapping("testLinkByPost")
    public String testLinkByPost() {
        HttpRequest.sendPost(app2Address + "/hello");
        return "ok";
    }

}
